/*
 * VisitBankAndDepositGold.java
 *
 * Created on March 27, 2007, 11:11 AM
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package ai9hells.pgaibe.chapter2.westworldwithmessaging;

import ai9hells.pgaibe.common.fsm.State;
import ai9hells.pgaibe.common.messaging.Telegram;

/**
 *
 * @author andre.bandarra
 */
public class VisitBankAndDepositGold extends State<Miner>{
    public static final State<Miner> INSTANCE = new VisitBankAndDepositGold();
    /** Creates a new instance of VisitBankAndDepositGold */
    public VisitBankAndDepositGold() {
    }

    public void enter(Miner m) {

        if (m.getLocation() != Locations.BANK){
            System.out.println(EntityNames.getNameOfEntity(m.getId())+": Goin' to the bank. Yes siree");
            m.setLocation(Locations.BANK);
        }
    }

    public void execute(Miner m) {
        m.addMoneyInBank(m.getGoldCarried());
        System.out.println(EntityNames.getNameOfEntity(m.getId())+": Depositing gold. Total savings now: "+m.getMoneyInBank());
        if (m.getMoneyInBank() >= Miner.COMFORT_LEVEL){
            System.out.println(EntityNames.getNameOfEntity(m.getId())+": WooHoo! Rich enough for now. Back home to mah li'lle lady");
            m.getStateMachine().changeState(GoHomeAndSleepTilRested.INSTANCE);
        } else {
            m.getStateMachine().changeState(EnterMineAndDigForNugget.INSTANCE);
        }
        
    }

    public void exit(Miner m) {
        System.out.println(EntityNames.getNameOfEntity(m.getId())+": Leavin' the bank");
    }

    public boolean onMessage(Miner m, Telegram t) {
        return false;
    }

}
